#include <iostream>
#include <stack>
using namespace std;

class MinStack
{
public:
    /** initialize your data structure here. */
    MinStack()
    = default;

    void push(int x)
    {
        if(_min.empty() || x <= _min.top())
        {
            _min.push(x);
        }
        _elem.push(x);
    }

    void pop()
    {
        if(_elem.top() == _min.top())
        {
            _min.pop();
        }
        _elem.pop();
    }

    int top()
    {
        return _elem.top();
    }

    int getMin()
    {
        return _min.top();
    }

private:
    std::stack<int> _elem;
    std::stack<int> _min;
};